<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<style>
			h5 {
				margin: 5px 7px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">添加布控人</h1>
			<button id="savebkr" type="button" class="mui-left mui-btn mui-btn-link mui-btn-nav mui-pull-right">
					保存
				</button>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded" style="margin: 5px;">
				<div class="mui-input-group">
					<div class="mui-input-row">
						<label>姓名</label>
						<input id="xm" type="text" placeholder="请输入姓名">
					</div>
					<div class="mui-input-row">
						<label>证件类型</label>
						<select id="zjlx">
							<option value="身份证" selected="selected">身份证</option>
							<option value="军官证">军官证</option>
						</select>
					</div>
					<div class="mui-input-row">
						<label>证件号码</label>
						<input id="zjhm" type="text" placeholder="请输入证件号码" />
					</div>
					<div class="mui-input-row">
						<label>人员类别</label>
						<select id="rylb">
							<option value="0" selected="selected">上访</option>
						</select>
					</div>
					<div class="mui-input-row">
						<label>范围类别</label>
						<select id="fwlb">
							<option value="0" selected="selected">地级</option>
							<option value="1">市级</option>
							<option value="2">省级</option>
						</select>
					</div>
				</div>
				<div class="mui-input-row" style="margin: 10px 5px;">
					<textarea id="bz" rows="5" placeholder="请输入备注" style="margin-bottom: 0;"></textarea>
				</div>
			</div>
			<div class="mui-content-padded" style="margin: 5px;">
				<div class="mui-input-group">
					<div class="mui-input-row">
						<label>报警接收人</label>
						<button id="toset" type="button" class="mui-btn-primary" style="margin-top: 0.25em;">设置(0)</button>
						<input type="hidden" id="bjjsr" />
					</div>
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="js/config.js"></script>
		<script type="text/javascript">
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				var myid = self.mainid;
				var adminuser = JSON.parse(localStorage.adminuser);
				var obj = null;
				$(function() {
					if(typeof(myid) != 'undefined') {
						$.get(dataDomain + "/dc/info/" + myid, function(req) {
							obj = req;
							$("#xm").val(req.realName);
							$("#zjlx").val(req.cardType);
							$("#zjhm").val(req.cardNo);
							$("#bz").val(req.remark);
							$("#bjjsr").val(req.alarmIds);
							setids(req.alarmIds);
						});
					}
					$("#toset").on("tap", function() {
						mui.openWindow({
							id: "alarm_receiving",
							url: "alarm_receiving.html",
							createNew: true,
							show: {
								aniShow: "none"
							},
							extras: {
								mainid: 1,
								setids: $("#bjjsr").val()
							}
						})
					});
					$("#savebkr").on("tap", function() {
						var xm = $("#xm").val();
						var zjlx = $("#zjlx").val();
						var zjhm = $("#zjhm").val();
						var bz = $("#bz").val();
						var bjjsr = $("#bjjsr").val();
						if(xm == '') {
							mui.alert("请输入姓名");
							return false;
						}
						if(zjlx == '') {
							mui.alert("请选择证件类型");
							return false;
						}
						if(zjhm == '') {
							mui.alert("请输入证件号码");
							return false;
						}
						//如果是修改
						if(typeof(myid) != 'undefined') {
							$.ajax({
								type: "PUT",
								url: dataDomain + "/dc/info/" + myid,
								data: {
									realName: xm,
									cardType: zjlx,
									cardNo: zjhm,
									remark: bz,
									alarmIds: bjjsr,
									state: obj.state,
									commitAuditDate: obj.commitAuditDate,
									currentAudit: obj.currentAudit,
									scopeType: obj.scopeType,
									manType: obj.manType,
									createUserId: adminuser.id
								},
								async: true,
								success: function(req) {
									if(req.status == 'ok') {
										mui.toast("修改成功");
									} else {
										mui.toast("提交失败，请稍候再试");
									}
								}
							});
						} else {
							$.post(dataDomain + "/dc/info", {
								realName: xm,
								cardType: zjlx,
								cardNo: zjhm,
								remark: bz,
								alarmIds: bjjsr,
								scopeType: $("#fwlb").val(),
								manType: $("#rylb").val()
							}, function(req) {
								if(req.status == 'ok') {
									mui.toast("保存成功");
									setTimeout(function() {
										plus.webview.currentWebview().close();
									}, 1000);
								} else {
									mui.toast("提交失败，请稍候再试");
								}
							});
						}
					});
				});
			});

			function setids(ids) {
				if(ids != "") {
					var arr = ids.split(",");
					$("#bjjsr").val(ids);
					$("#toset").html("设置(" + arr.length + ")");
				} else {
					var arr = ids.split(",");
					$("#bjjsr").val("");
					$("#toset").html("设置(0)");
				}

			}
		</script>
	</body>

</html>